<template>
  <div class="stock-warning-statistics">
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <span>库存预警统计</span>
        </div>
      </template>
      <div class="content">
        <el-row :gutter="20">
          <el-col :span="12">
            <div class="total-count">
              <h3>总记录数</h3>
              <p>{{ statistics.total_count }}</p>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="warning-count">
              <h3>预警记录数</h3>
              <p>{{ statistics.warning_count }}</p>
            </div>
          </el-col>
        </el-row>
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import request from '@/utils/request'
import { ElMessage } from 'element-plus'

const statistics = ref({
  total_count: 0,
  warning_count: 0
})

const getStatistics = async () => {
  try {
    const res = await request.get('/api/stock-warning/statistics/')
    statistics.value = res
  } catch (error) {
    console.error('获取库存预警统计失败:', error)
  }
}

onMounted(() => {
  getStatistics()
})
</script>

<style scoped>
.stock-warning-statistics {
  padding: 20px;
}

.box-card {
  width: 100%;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.content {
  margin-top: 20px;
}

.total-count, .warning-count {
  text-align: center;
}

.total-count h3, .warning-count h3 {
  margin: 0;
  font-size: 18px;
}

.total-count p, .warning-count p {
  margin: 10px 0 0;
  font-size: 24px;
  color: #67C23A; /* Element Plus 的成功颜色 */
}
</style>
